package com.kuaidian.service;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import com.kuaidian.util.KdJedisPool;

@Service
public class RedisService {

    private static Logger logger = Logger.getLogger(RedisService.class);  

    //@Autowired
    //private JedisPool jedisPool;
    
    private JedisPool jedisPool = KdJedisPool.getJedisPool();
    
    
    public void cacheLoginedUser(Integer user_id, String token){
    	try(Jedis jedis = jedisPool.getResource()) {
    		jedis.set("user_id:" + user_id, token);
    	} 
    }
    
    public String getCachedLoginedUser(Integer user_id){
    	try(Jedis jedis = jedisPool.getResource()) {
    		String token = jedis.get("user_id:" + user_id);
    		return token;
    	} 
    }
    
    public void delCachedLoginedUser(Integer user_id){
    	try(Jedis jedis = jedisPool.getResource()) {
    		jedis.del("user_id:" + user_id);
    		
    	} 
    }
    
    
    
    
}
